﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using MvcEngine.Blog.Models.Entities;
using MvcEngine.Core;
using MvcEngine.Core.Extensions;
using MvcEngine.Mvc.Extensions;
using MvcEngine.Core.Helpers;
using MvcEngine.Mvc.ModelBinders;

namespace MvcEngine.Blog.ModelBinders
{
    public class BlogPostCommentModelBinder : ModelBinderBase
    {
        public override object Bind(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            HttpRequestBase request = controllerContext.HttpContext.Request;
            BlogPostComment comment = IoC.Resolve<BlogPostComment>();
            comment.Author = request.Form.Get("Author").HtmlEncode();
            comment.Comment = request.Form.Get("Comment").HtmlEncode();
            comment.Email = request.Form.Get("Email").HtmlEncode();
            comment.Website = request.Form.Get("Website").HtmlEncode();
            comment.Ip = controllerContext.HttpContext.Request.UserHostAddress;

            Validate(comment, controllerContext);

            return comment;
        }
    }
}
